<template>
  <view class="payments-container">
    <view class="payments-list">
      <view v-for="(payment, index) in payments" :key="index" class="payment-item">
        <view class="payment-header">
          <text class="payment-time">{{ payment.payTime }}</text>
          <text :class="['payment-status', payment.status]">{{ getStatusText(payment.status) }}</text>
        </view>
        <view class="payment-content" @click="viewDetail(payment.id)">
          <text class="payment-title">{{ payment.title }}</text>
          <text class="payment-amount">¥{{ payment.amount.toFixed(2) }}</text>
          <text class="payment-desc">{{ payment.description }}</text>
        </view>
      </view>
    </view>
    
    <view v-if="payments.length === 0" class="empty-state">
      <text>暂无缴费记录</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      payments: [
        
        {
          id: 3,
          title: '2025年2月电费',
          description: '用电量: 120度',
          amount: 84.60,
          payTime: '',
          status: 'paid'
        }
      ]
    }
  },
  
  onLoad() {
    // this.fetchPaymentHistory()
  },
  
  methods: {
    async fetchPaymentHistory() {
      try {
        // 从后端获取缴费历史数据
        const res = await this.$api.getPaymentHistory()
        this.payments = res.data
      } catch (error) {
        uni.showToast({
          title: '获取数据失败',
          icon: 'none'
        })
      }
    },
    
    getStatusText(status) {
      const statusMap = {
        'paid': '已缴费',
        'unpaid': '待缴费',
        'overdue': '已逾期',
        'processing': '处理中'
      }
      return statusMap[status] || status
    },
    
    viewDetail(id) {
      uni.navigateTo({
        url: `/pages/my/payment-detail?id=${id}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.payments-container {
  padding: 20rpx;
  
  .payments-list {
    .payment-item {
      background: #fff;
      border-radius: 12rpx;
      padding: 20rpx;
      margin-bottom: 20rpx;
      
      .payment-header {
        display: flex;
        justify-content: space-between;
        margin-bottom: 16rpx;
        
        .payment-time {
          color: #999;
          font-size: 24rpx;
        }
        
        .payment-status {
          font-size: 24rpx;
          
          &.paid { color: #19be6b; }
          &.unpaid { color: #ff9900; }
          &.overdue { color: #fa3534; }
          &.processing { color: #2979ff; }
        }
      }
      
      .payment-content {
        .payment-title {
          font-size: 28rpx;
          font-weight: bold;
          margin-bottom: 8rpx;
        }
        
        .payment-amount {
          font-size: 32rpx;
          color: #fa3534;
          font-weight: bold;
          margin-bottom: 8rpx;
        }
        
        .payment-desc {
          font-size: 26rpx;
          color: #666;
        }
      }
    }
  }
  
  .empty-state {
    text-align: center;
    padding: 60rpx 0;
    color: #999;
  }
}
</style>
